package shuaige.jdk.函数式接口.自定义排序_Comparator;

import java.util.Arrays;
import java.util.Comparator;

public class Comparator_具体实现 {

    public static Comparator<String> comparator = new Comparator<>() {
        @Override
        public int compare(String s1, String s2) {
            return s1.compareTo(s2);
        }
    };

    public static void main(String[] args) {
        String的调用_使用函数式编程();
    }

    public static void String的调用_使用函数式编程_方法引用() {
        String[] array = {"3", "2", "5", "1"};
        Arrays.sort(array, String::compareTo);
        for (String s : array) {
            System.out.println(s);
        }
    }

    public static void String的调用_使用函数式编程() {
        String[] array = {"3", "2", "5", "1"};
        Arrays.sort(array, (s1, s2) -> s1.compareTo(s2));
        for (String s : array) {
            System.out.println(s);
        }
    }

    public static void String的调用_使用函数() {
        String[] array = {"3", "2", "5", "1"};
        Arrays.sort(array, comparator);
        for (String s : array) {
            System.out.println(s);
        }
    }
}
